/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package arbitration.logic;

import com.toedter.calendar.HolidayPolicy;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author prophet
 */
public class CalcUtils {

    public static Date getPaymentEndDate(Date date, Integer days, HolidayPolicy holidayPolicy){
        Calendar deliveryDate=new GregorianCalendar();
        deliveryDate.setTime(date);
        deliveryDate.add(Calendar.DATE, days);
        System.out.println(calendarToString(deliveryDate));
        if(holidayPolicy!=null)
        while(holidayPolicy.isHoliday(deliveryDate)){
            deliveryDate.add(Calendar.DATE, 1);            
        }
        return deliveryDate.getTime();
    }

    public static String dateToString(Date date){
        SimpleDateFormat dateFormatter=(SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM);        
        return dateFormatter.format(date);        
    }
    public static String calendarToString(Calendar calendar){
        SimpleDateFormat dateFormatter=(SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM);        
        return dateFormatter.format(calendar.getTime());
    }
}
